<template>
  <div class="layout">
    <el-container style="height: 100vh; border: 1px solid #eee">
      <!-- 左侧导航 -->
      <el-aside width="200px"
                style="background-color: rgb(238, 241, 246)">
        <el-menu router
                 :default-openeds="['/layout']">
          <el-submenu index="/layout">
            <template slot="title"><i class="el-icon-message"></i>基础版</template>
            <el-menu-item index="/layout/">统计</el-menu-item>
            <el-menu-item index="/layout/xiaohuo">销售</el-menu-item>
            <el-menu-item index="/layout/jinhuo">进货</el-menu-item>
            <el-menu-item index="/layout/kucun">库存</el-menu-item>
          </el-submenu>
        </el-menu>
      </el-aside>

      <!-- 右侧内容显示 -->
      <el-container>
        <!-- 顶部栏 -->
        <el-header style="
            text-align: right;
            font-size: 12px;
            padding-top: 20px;
            box-sizing: border-box;
            border-bottom: 1px solid rgb(190, 52, 49);
          ">
          <el-dropdown @command="handleCommand">
            <i class="el-icon-setting"
               style="margin-right: 15px"></i>

            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item command="out">退出登陆</el-dropdown-item>
              <el-dropdown-item command="resetPass">修改密码</el-dropdown-item>
              <el-dropdown-item command="resetRule">修改权限</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
          <span>{{ users.username }}</span>
        </el-header>

        <el-main style="padding:0">
          <!-- 路由试图 -->
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
import { mapActions, mapState } from 'vuex';
export default {
  computed: {
    ...mapState(['users']),
  },
  methods: {
    ...mapActions(['actUser']),
    handleCommand (command) {
      if (command === 'out') {
        // 走接口
        this.actUser({ state: 0, username: this.users.username }).then((res) => {
          if (res.code) {
            this.$message({
              message: res.msg || '已退出登录',
              type: 'success',
            });
            this.$store.commit('setUser', { token: null, loginState: 0 });
            // 跳转到登录页
            this.$router.push('user');
          }
        });
      }
    },
  },
};
</script>

<style></style>
